<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 12-8-16
 * Time: 下午3:18
 * To change this template use File | Settings | File Templates.
 */
class model_game extends MY_Model
{
    public function joinGame(array $data)
    {
        $info = array(
            'passport' => $data['passport'],
            'nickname' => $data['nickname'],
            'dan' => $data['dan'],
            'chess_will' => $data['chess_will'],
            'create_time' => date('Y-m-d H:i:s', TIMESTAMP)
        );

        $this->db->insert('game_apply', $info);
        return $this->db->insert_id();
    }

    public function getGameUser($passport)
    {
        return $uInfo = $this->db->select('*')->get_where('game_apply', array('passport' => $passport))->row_array();
    }

    public function getApplyList($limit = 20 ,$offset = 0, $field = '*', $where = null, $order = null)
    {
        $this->db->select($field);
        $this->db->from('game_apply');
        $where && $this->db->where($where);
        $order && $this->db->order_by($order);
        $this->db->limit($limit, $offset);
        return $this->db->get()->result_array();
    }

    public function getApplyCount($where = null)
    {
        $this->db->select('*')->from('game_apply');
        $where && $this->db->where($where);
        return $this->db->count_all_results();
    }
}
